package com.dnui.seven2.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dnui.seven2.entity.Announcement;
import com.dnui.seven2.service.AnnouncementService;
import com.dnui.seven2.mapper.AnnouncementMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author fengy
 * @description 针对表【announcement】的数据库操作Service实现
 * @createDate 2022-10-16 10:08:34
 */
@Service
public class AnnouncementServiceImpl extends ServiceImpl<AnnouncementMapper, Announcement>
        implements AnnouncementService{


    @Autowired
    AnnouncementMapper announcementMapper;

    @Override
    public List<Announcement> queryAnnouncements(Integer currentPageNum, Integer everyPage) {
        Page page=new Page(currentPageNum,everyPage);
        announcementMapper.selectPage(page, null);
        return page.getRecords();
    }

    @Override
    public Announcement queryById(Integer announcementId) {
        return announcementMapper.selectById(announcementId);
    }

    @Override
    public void saveAnnouncement(Announcement announcement) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.eq("announcement_id",announcement.getAnnouncementId());
        Announcement ann = announcementMapper.selectOne(queryWrapper);
        if (ann==null){//账号不存在，未重复
            announcementMapper.insert(announcement);
        }
    }

    @Override
    public void deleteAnnouncement(Integer announcementId) {
        announcementMapper.deleteById(announcementId);
    }

    @Override
    public void updateAnnouncement(Announcement announcement) {
        announcementMapper.updateById(announcement);
    }
}




